<template>
	<view class="page">
		<pageTxt>
			<!--  v-model="dataList" @query="queryList" -->
			<z-paging ref="paging" refresher-only @onRefresh="onRefresh"
				:paging-style="{ 'background-color': '#f7f7f7', height: '100%', width: '100%' }">
				<!-- 头部 -->
				<template slot="top">
					<u-navbar title="优惠审批详情" :autoBack="true" :fixed="false"></u-navbar>
					<view class="tab-box">
						<u-tabs :current="tabIndex" @click="tabClickFunc" :list="tablist" inactiveStyle="color: #919092;"
							activeStyle="color: #3B75FF;" lineColor="#3B75FF"></u-tabs>
					</view>
				</template>
				<!-- 内容 -->
				<template v-if="dataObj">
					<view class="detail-content-box" v-if="tabIndex == 0">
						<u-empty v-if="!$fieldShowFunc('14-xmxx') && !$fieldShowFunc('14-yhspxx')" marginTop="300rpx"
							icon="https://hzybucket.obs.cn-south-1.myhuaweicloud.com/we_chat/no-msg2.png" text=" "></u-empty>
						<view class="item-box" v-if="$fieldShowFunc('14-xmxx')">
							<view class="title">项目信息</view>
							<view class="item-box-item flex jb" v-if="$fieldShowFunc('yh_glxm')">
								<text class="txt">项目名称</text>
								<view class="content">
									{{ dataObj.project_name || '--' }}
								</view>
							</view>
							<view class="item-box-item flex jb" v-if="$fieldShowFunc('yh_xmbh')">
								<text class="txt">项目编号</text>
								<view class="content">
									<text class="txt-btn" @click="navToProjectFunc">{{ dataObj.project_number || '--' }}</text>
								</view>
							</view>
							<view class="item-box-item flex jb" v-if="$fieldShowFunc('yh_xmpp')">
								<text class="txt">项目品牌</text>
								<view class="content">
									{{ dataObj.brand_name || '--' }}
								</view>
							</view>
							<view class="item-box-item flex jb" v-if="$fieldShowFunc('yh_xmlx')">
								<text class="txt">项目类型</text>
								<view class="content">
									{{ dataObj.store_type_name || '--' }}
								</view>
							</view>
							<view class="item-box-item flex jb" v-if="$fieldShowFunc('yh_bjdxx') && dataObj.type == 1">
								<text class="txt">报价单信息</text>
								<view class="content">
									<text class="txt-btn">{{ dataObj.project_quotation_num || '--' }}</text>
								</view>
							</view>
						</view>
						<view class="item-box" v-if="$fieldShowFunc('14-yhspxx')">
							<view class="title">优惠审批信息</view>
							<view class="item-box-item flex jb" v-if="$fieldShowFunc('yh_splx')">
								<text class="txt">审批类型</text>
								<view class="content">
									{{ dataObj.type == 1 ? '对客报价优惠' : '结算优惠' }}
								</view>
							</view>
							<view class="item-box-item flex jb" v-if="$fieldShowFunc('yh_ysbjje')">
								<text class="txt">{{ dataObj.type == 1 ? '预算报价金额' : '结算报价金额' }}</text>
								<view class="content">
									{{ dataObj.budget_quotation_amount ? dataObj.budget_quotation_amount + '元' : '--' }}
								</view>
							</view>
							<view class="item-box-item flex jb" v-if="$fieldShowFunc('yh_yjqyje')">
								<text class="txt">{{ dataObj.type == 1 ? '预计签约金额' : '预计结算金额' }}</text>
								<view class="content">
									{{ dataObj.expected_signing_amount ? dataObj.expected_signing_amount + '元' : '--' }}
								</view>
							</view>
							<view class="item-box-item flex jb" v-if="$fieldShowFunc('yh_shzt')">
								<text class="txt">审批状态</text>
								<view class="content">
									<template v-if="dataObj.customer_director_review == 1">审核中</template>
									<template v-if="dataObj.customer_director_review == 2">审核通过</template>
									<template v-if="dataObj.customer_director_review == 3">审核拒绝</template>
									<template v-if="dataObj.customer_director_review == 4">已废弃</template>
								</view>
							</view>
							<view class="item-box-item flex jb" v-if="$fieldShowFunc('yh_shjjly')">
								<text class="txt">审批意见</text>
								<view class="content">
									{{ dataObj.reason_refusal || '--' }}
								</view>
							</view>
							<view class="item-box-item flex jb" v-if="$fieldShowFunc('yh_yhje')">
								<text class="txt">优惠金额</text>
								<view class="content">
									{{ dataObj.discount_amount ? dataObj.discount_amount + '元' : '--' }}
								</view>
							</view>
							<view class="item-box-item flex jb" v-if="$fieldShowFunc('yh_yhhlrje')">
								<text class="txt">优惠后利润金额</text>
								<view class="content">
									{{ dataObj.remaining_profit_amount ? dataObj.remaining_profit_amount + '元' : '--' }}
								</view>
							</view>
							<view class="item-box-item flex jb" v-if="$fieldShowFunc('yh_yhhcblrl')">
								<text class="txt">优惠后成本利润率</text>
								<view class="content">
									{{ dataObj.remaining_cost_profit_ratio ? dataObj.remaining_cost_profit_ratio + '%' : '--' }}
								</view>
							</view>
							<view class="item-box-item flex jb" v-if="$fieldShowFunc('yh_yhqlrje')">
								<text class="txt">优惠前利润金额</text>
								<view class="content">
									{{ dataObj.profit_amount ? dataObj.profit_amount + '元' : '--' }}
								</view>
							</view>
							<view class="item-box-item flex jb" v-if="$fieldShowFunc('yh_yhqcblrl')">
								<text class="txt">优惠前成本利润率</text>
								<view class="content">
									{{ dataObj.cost_profit_ratio ? dataObj.cost_profit_ratio + '%' : '--' }}
								</view>
							</view>
							<view class="item-box-item flex jb" v-if="$fieldShowFunc('yh_cjsj')">
								<text class="txt">创建时间</text>
								<view class="content">
									{{ dataObj.created_at || '--' }}
								</view>
							</view>
							<view class="item-box-item flex jb" v-if="$fieldShowFunc('yh_cjr')">
								<text class="txt">创建人</text>
								<view class="content">
									{{ dataObj.name || '--' }}
								</view>
							</view>
						</view>
					</view>
					<!-- 历史 -->
					<view class="detail-content-box" v-if="tabIndex == 1">
						<view class="item-box">
							<u-empty v-if="!logList.length" marginTop="300rpx"
								icon="https://hzybucket.obs.cn-south-1.myhuaweicloud.com/we_chat/no-msg2.png" text=" "></u-empty>
							<u-steps current="0" direction="column" dot activeColor="#3b75ff" inactiveColor="#3b75ff">
								<u-steps-item v-for="(item, index) in logList" :key="index">
									<template slot="desc">
										<view class="steps-title flex ac jb">
											<view class="steps-title-title">{{ item.updated_at }}</view>
											<view class="steps-title-user-data-box flex ac jc">
												<image class="avater-box" :src="item.handlers_image" mode="aspectFit"></image>
												<view class="user-name u-line-1">
													{{ item.handlers_name + '-' + item.handlers_position }}
												</view>
											</view>
										</view>
										<view class="steps-desc">
											<view class="steps-desc-title">
												{{ item.content }}
											</view>
											<template v-if="item.log_status == 260">
												<view class="steps-desc-box flex ac" v-if="$fieldShowFunc('yh_shjjly')">
													<view class="steps-desc-box-title">审批意见</view>
													<view class="steps-desc-box-desc">
														{{ item.form_data.reason_refusal || '--' }}
													</view>
												</view>
											</template>
											<template v-if="item.log_status == 270">
												<view class="steps-desc-box flex ac" v-if="$fieldShowFunc('yh_shjjly')">
													<view class="steps-desc-box-title">审批意见</view>
													<view class="steps-desc-box-desc">
														{{ item.form_data.reason_refusal || '--' }}
													</view>
												</view>
											</template>
											<template v-if="item.log_status == 255">
												<view class="steps-desc-box flex ac" v-if="$fieldShowFunc('yh_ysbjje')">
													<view class="steps-desc-box-title">
														{{ dataObj.type == 1 ? '预算报价金额' : '结算报价金额' }}
													</view>
													<view class="steps-desc-box-desc">
														{{ item.form_data.budget_quotation_amount ? item.form_data.budget_quotation_amount + '元' : '--' }}
													</view>
												</view>
												<view class="steps-desc-box flex ac" v-if="$fieldShowFunc('yh_yjqyje')">
													<view class="steps-desc-box-title">
														{{ dataObj.type == 1 ? '预计签约金额' : '预计结算金额' }}
													</view>
													<view class="steps-desc-box-desc">
														{{ item.form_data.expected_signing_amount ? item.form_data.expected_signing_amount + '元' : '--' }}
													</view>
												</view>
												<view class="steps-desc-box flex ac" v-if="$fieldShowFunc('yh_yhje')">
													<view class="steps-desc-box-title">优惠金额</view>
													<view class="steps-desc-box-desc">
														{{ item.form_data.discount_amount ? item.form_data.discount_amount + '元' : '--' }}
													</view>
												</view>
												<view class="steps-desc-box flex ac" v-if="$fieldShowFunc('yh_yhhlrje')">
													<view class="steps-desc-box-title">优惠后利润金额</view>
													<view class="steps-desc-box-desc">
														{{ item.form_data.remaining_profit_amount ? item.form_data.remaining_profit_amount + '元' : '--' }}
													</view>
												</view>
												<view class="steps-desc-box flex ac" v-if="$fieldShowFunc('yh_yhhcblrl')">
													<view class="steps-desc-box-title">优惠后成本利润率</view>
													<view class="steps-desc-box-desc">
														{{ item.form_data.remaining_cost_profit_ratio ? item.form_data.remaining_cost_profit_ratio + '%' : '--' }}
													</view>
												</view>
												<view class="steps-desc-box flex ac" v-if="$fieldShowFunc('yh_yhqlrje')">
													<view class="steps-desc-box-title">优惠前利润金额</view>
													<view class="steps-desc-box-desc">
														{{ item.form_data.profit_amount ? item.form_data.profit_amount + '元' : '--' }}
													</view>
												</view>
												<view class="steps-desc-box flex ac" v-if="$fieldShowFunc('yh_yhqcblrl')">
													<view class="steps-desc-box-title">优惠前成本利润率</view>
													<view class="steps-desc-box-desc">
														{{ item.form_data.cost_profit_ratio ? item.form_data.cost_profit_ratio + '%' : '--' }}
													</view>
												</view>
											</template>
										</view>
									</template>
								</u-steps-item>
							</u-steps>
						</view>
					</view>
				</template>
				<view class="bottom-btn-box flex ac jb" slot="bottom">
					<view style="width: 100%" v-if="!loading">
						<judgeBtn info :per_arr="per_arr" :btns="btns" objectType="discount"
							:state="dataObj.customer_director_review" :item="dataObj" @change="btnsChange"></judgeBtn>
					</view>
				</view>
			</z-paging>
			<!-- 操作组件 -->
			<discountOperate :value.sync="per_name" :oper_item="oper_item" @submit="handleSubmit"></discountOperate>
		</pageTxt>
	</view>
</template>

<script>
	export default {
		provide() {
			return {
				providedData: this.btns
			};
		},
		data() {
			return {
				logList: [],
				loading: false,
				dataObj: '',
				tabIndex: 0,
				tablist: [{
						name: '详情'
					},
					{
						name: '历史记录'
					}
				],
				per_arr: [], //权限列表
				// 操作按钮
				btns: [{
						per_name: 'discount_examine',
						func: (item) => {
							if (item.review_status == 10 && (item.is_retrial == 2 || item.is_retrial == 3)) {
								return true;
							} else {
								return false;
							}
						},
						name: '审核优惠审批'
					},
					{
						per_name: 'discount_discountReviewPassed2',
						func: (item) => {
							if (item.is_retrial == 3 && item.review_status == 20) {
								return true;
							} else {
								return false;
							}
						},
						name: '复审优惠审批'
					},
					{
						per_name: 'discount_discountInvalidation',
						func: (item) => {
							if (item.customer_director_review != 4) {
								return true;
							} else {
								return false;
							}
						},
						name: '审批作废'
					}
				],
				// 操作相关
				per_name: '',
				oper_item: {}
			};
		},
		onLoad(option) {
			this.discountApprovalDetails(option.id);
			// 获取权限
			this.$Api
				.getHtmlAuthority({
					path: '/discountApproval'
				})
				.then((res) => {
					console.log(res, 'getHtmlAuthority');
					if (res.code == 200) {
						this.per_arr = res.data.permission;
					}
				});
		},
		onShow() {
			if (this.dataObj) {
				this.discountApprovalDetails(this.dataObj.id);
			}
		},
		methods: {
			// 操作反馈
			handleSubmit(e) {
				this.onRefresh();
			},
			// 操作事件
			btnsChange(e) {
				console.log(e);
				this.per_name = e.per_name;
				this.oper_item = e.item;
			},
			onRefresh() {
				this.discountApprovalDetails(this.dataObj.id);
				this.$refs.paging.complete();
			},
			tabClickFunc(e) {
				this.tabIndex = e.index;
			},
			// 优惠审批详情
			discountApprovalDetails(discount_id) {
				this.loading = true;
				this.$Apipc
					.discountApprovalDetails({
						discount_id
					})
					.then((res) => {
						console.log(res, '优惠审批详情');
						this.loading = false;
						if (res.code == 200) {
							res.data.log_list.forEach((item) => {
								item.form_data = JSON.parse(item.form_data);
							});
							this.dataObj = res.data;
							this.logList = res.data.log_list ? res.data.log_list : [];
						}
					});
			},
			// 去项目详情
			navToProjectFunc() {
				uni.navigateTo({
					url: '/pagesB/projectDetail/projectDetail?id=' + this.dataObj.project_id
				});
			}
		}
	};
</script>

<style lang="scss" scoped>
	@import 'discountApprovalDetail.scss';
</style>